﻿//<!--******************************************************************************************-->
//
//  警告: 本電腦程式著作受著作權法及國際公約之保護。
//  未經授權擅自複製或散佈本電腦程式著作之全部或部分
//  ，將導致嚴厲的民事或刑事處份，且將被依法提起最大
//  範圍的追訴。
//
//  CopyRight (C) Galaxy Software Service
//<!--******************************************************************************************-->
function GSSAddListBoxItem(vstrURL,viSearchType,vintOpenType,vstrWinName,vstrWinFeatures,vblnWinReplace){
	var vntReturn='';	
	var objDocument=GSSGetDocument();
	var objBtn=event.srcElement;
	var objForm=GSSGetParentElementByTag(objBtn,'FORM');
	var objContainer=GSSGetParentElementByTag(event.srcElement,'TABLE').rows[0].cells[0];
	var colChildren=objContainer.children;
	var objListBox=colChildren[0];
	var blnRtn=GSSgetFilterAtrr(objBtn,vstrURL,vintOpenType,vstrWinName,vstrWinFeatures,vblnWinReplace);
	if(!blnRtn) return false;
	var intDeep=document.all['GSStxtFunDeep'].value;
	if(intDeep!=''){
		intDeep=parseInt(intDeep)+1;}
	else{
		intDeep=1;}		
	if(GSS_DATAFLD==''){
		strDataFld='CODE_ID,CODE_NAME';}
	else{
		strDataFld=GSS_DATAFLD;}	
	var strURL = GSS_URL + '?GSStxtFunDeep=' + intDeep + '&strFilter=' + escape(GSS_FILTER) + '&strDataFld=' + escape(GSS_DATAFLD);
	if(GSS_EXATTR!='') strURL +=GSS_EXATTR;
	strURL += '&nameListBox=' + objListBox.name;
	strURL += '&GSSStopRec=Y';		//避免關閉視窗後，連接至下一頁，再回上一頁，發生錯誤
	GSScreateInputElm(objDocument,objForm,'GSSnameSrcID','HIDDEN','display:none;',objListBox.name);
	
	if (GSS_OPENTYPE==1){
		window.open(strURL,GSS_WINNAME,GSS_WINFEATURES,GSS_WINREPLACE);}
	else{
		vntReturn=window.showModalDialog(strURL,GSS_WINNAME,GSS_WINFEATURES);
		if((vntReturn) && (vntReturn!='')){
			GSSaddOptionByStr(objListBox,vntReturn);}
	}
}

function GSSaddOptionByStr(vobjCbo,sOptContent){
	if(sOptContent=='') return false;
	var arrItem;
	var sOptText;
	var sOptValue;
	var arrOption=sOptContent.split('\\,');
	for(var i=0;i<arrOption.length;i++){
     		var objOption = document.createElement('OPTION');
     		arrItem=arrOption[i].split('\\|');
     		objOption.value=arrItem[0];
     		objOption.text=arrItem[1];
     		if (!GSSisOptionExists(vobjCbo,objOption.value)) vobjCbo.options.add(objOption);
     	}
}

function GSSisOptionExists(vobjCbo,vstrCompareOpt,vintCompareType){
	var strCompared;
	if (typeof(vintCompareType)!='number') vintCompareType=1;
	for (var i=0;i<vobjCbo.length;i++){
		if (vintCompareType==1) strCompared=vobjCbo.options[i].value;
		if (vintCompareType==2) strCompared=vobjCbo.options[i].text;
		if (vstrCompareOpt ==strCompared) return true;
	}
	return false;
}

function GSSRemoveListBoxItem(){
	var objListBox;
	if(event.srcElement.tagName=='BUTTON'){
		var objBtn=event.srcElement;
		var objContainer=GSSGetParentElementByTag(event.srcElement,'SPAN').children[0].children[0].children[0].children[0];
		var colChildren=objContainer.children;
		objListBox=colChildren[0];}
	else{
		objListBox=event.srcElement;}
		
   	var iCount=objListBox.options.length;
   	for (i=iCount-1;i>=0;i--){
   		if(objListBox.options[i].selected){
      		objListBox.options[i].selected=false;
      		objListBox.remove(i);}
   }  
}   